import json
import pytest
from typing import Any, Dict

def assert_successful_response(response: Any, logger: Any) -> Dict:
    """验证成功响应"""
    data = json.loads(response.data)
    logger.info(f"\nAPI Response Details:")
    logger.info(f"Status Code: {response.status_code}")
    
    if not data.get('success'):
        logger.info(f"Error Type: {data.get('error_type')}")
        logger.info(f"Error Message: {data.get('error')}")
        pytest.fail(f"API call failed: {data.get('error')}")
    else:
        logger.info("Success: True")
        if 'response' in data:
            logger.info(f"Response: {data.get('response')[:100]}...")
    
    assert response.status_code == 200
    assert data['success'] == True
    return data

def assert_error_response(response: Any, expected_status: int = 400) -> Dict:
    """验证错误响应"""
    data = json.loads(response.data)
    assert response.status_code == expected_status
    assert data['success'] == False
    assert 'error' in data
    return data 